package com.ruoyi.supply.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.supply.service.impl.AdSpotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.supply.domain.AdSpot;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告位Controller
 * 
 * @author Ryan
 * @date 2025-06-02
 */
@RestController
@RequestMapping("/supply/spot")
@Api(tags = "广告位管理")
public class AdSpotController extends BaseController
{
    @Autowired
    private AdSpotService adSpotService;

    /**
     * 查询广告位列表
     */
//    @PreAuthorize("@ss.hasPermi('supply:spot:list')")
    @GetMapping("/list")
    @ApiOperation("查询广告位列表")
    public TableDataInfo list(AdSpot adSpot)
    {
        startPage();
        List<AdSpot> list = adSpotService.selectAdSpotList(adSpot);
        return getDataTable(list);
    }

    /**
     * 导出广告位列表
     */
//    @PreAuthorize("@ss.hasPermi('supply:spot:export')")
    @Log(title = "广告位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdSpot adSpot)
    {
        List<AdSpot> list = adSpotService.selectAdSpotList(adSpot);
        ExcelUtil<AdSpot> util = new ExcelUtil<AdSpot>(AdSpot.class);
        util.exportExcel(response, list, "广告位数据");
    }

    /**
     * 获取广告位详细信息
     */
//    @PreAuthorize("@ss.hasPermi('supply:spot:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取广告位详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(adSpotService.selectAdSpotById(id));
    }

    /**
     * 新增广告位
     */
//    @PreAuthorize("@ss.hasPermi('supply:spot:add')")
    @Log(title = "广告位", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增广告位")
    public AjaxResult add(@RequestBody AdSpot adSpot)
    {
        return toAjax(adSpotService.insertAdSpot(adSpot));
    }

    /**
     * 修改广告位
     */
//    @PreAuthorize("@ss.hasPermi('supply:spot:edit')")
    @Log(title = "广告位", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改广告位")
    public AjaxResult edit(@RequestBody AdSpot adSpot)
    {
        return toAjax(adSpotService.updateAdSpot(adSpot));
    }

    /**
     * 删除广告位
     */
//    @PreAuthorize("@ss.hasPermi('supply:spot:remove')")
    @ApiOperation("删除")
    @Log(title = "广告位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adSpotService.deleteAdSpotByIds(ids));
    }
}
